package com.atbun.eduservice.controller.front;

import com.atbun.commonutils.R;
import com.atbun.eduservice.entity.EduCourse;
import com.atbun.eduservice.entity.EduTeacher;
import com.atbun.eduservice.service.EduCourseService;
import com.atbun.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description : 客户端讲师列表接口
 * @Author : mayp
 * @Date: 2020-05-16 22:17
 */
@RestController
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService eduTeacherService;

    @Autowired
    private EduCourseService eduCourseService;

    /**
     * 分页获取讲师列表
     * @param page
     * @param limit
     * @return
     */
    @PostMapping("getTeacherFrontPage/{page}/{limit}")
    public R getTeacherFrontPage(@PathVariable long page,@PathVariable long limit){
        Page<EduTeacher> parman = new Page<>(page,limit);
        Map<String,Object> map = this.eduTeacherService.pageTeacher(parman);
        return R.ok().data(map);
    }

    /**
     * 根据讲师id查询讲师详情。
     * @param id
     * @return
     */
    @GetMapping("getTeacherInfo/{id}")
    public R getTeacherInfo(@PathVariable String id){
        EduTeacher eduTeacher = this.eduTeacherService.getTeacherInfo(id);
        List<EduCourse> eduCourseList = eduCourseService.queryCourseByTeacherId(id);
        return R.ok().data("eduTeacher",eduTeacher).data("eduCourseList",eduCourseList);
    }
}
